﻿using ELab.Exceptions;

namespace ELab.Communication.Messages
{
    public static class ELabMessageFactory
    {
        public const int MessageTypeIdELabDataTransferMessage = 1;
        public const int MessageTypeIdELabOperationResultMessage = 2;
        public const int MessageTypeIdELabPingMessage = 3;
        public const int MessageTypeIdELabRegisterMessage = 4;
        public const int MessageTypeIdELabChangeCommunicationWayMessage = 5;
        public const int MessageTypeIdELabControllerMessage = 6;
        public const int MessageTypeIdELabDataTransferResponseMessage = 7;

        public static ELabMessage CreateMessageByTypeId(int messageTypeId)
        {
            switch (messageTypeId)
            {
                case MessageTypeIdELabDataTransferMessage:
                    return new ELabDataTransferMessage();
                case MessageTypeIdELabOperationResultMessage:
                    return new ELabOperationResultMessage();
                case MessageTypeIdELabPingMessage:
                    return new ELabPingMessage();
                case MessageTypeIdELabRegisterMessage:
                    return new ELabRegisterMessage();
                case MessageTypeIdELabChangeCommunicationWayMessage:
                    return new ELabChangeCommunicationWayMessage();
                case MessageTypeIdELabControllerMessage:
                    return new ELabControllerMessage();
                case MessageTypeIdELabDataTransferResponseMessage:
                    return new ELabDataTransferResponseMessage();
                default:
                    throw new ELabException("Unknown MessageTypeId: " + messageTypeId);
            }
        }
    }
}
